﻿namespace TS2015.Models
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;

    public partial class TS2015Context : DbContext
    {
        public TS2015Context()
            : base("name=TS2015Context")
        {
        }

        public static TS2015Context Create()
        {
            return new TS2015Context();
        }

        public virtual DbSet<TbChucNang> TbChucNangs { get; set; }
        public virtual DbSet<TbChucNang_Quyen> TbChucNang_Quyen { get; set; }
        public virtual DbSet<TbChuyenNganh> TbChuyenNganhs { get; set; }
        public virtual DbSet<TbDanToc> TbDanTocs { get; set; }
        public virtual DbSet<TbDiemTotNghiep> TbDiemTotNghieps { get; set; }
        public virtual DbSet<TbDoiTuongUuTien> TbDoiTuongUuTiens { get; set; }
        public virtual DbSet<TbHeDaoTao> TbHeDaoTaos { get; set; }
        public virtual DbSet<TbHuyen> TbHuyens { get; set; }
        public virtual DbSet<TbKhoa> TbKhoas { get; set; }
        public virtual DbSet<TbKhoiThi> TbKhoiThis { get; set; }
        public virtual DbSet<TbKhuVuc> TbKhuVucs { get; set; }
        public virtual DbSet<TbQuyen> TbQuyens { get; set; }
        public virtual DbSet<TbTheLoai> TbTheLoais { get; set; }
        public virtual DbSet<TbMonTotNghiep> TbMonTotNghieps { get; set; }
        public virtual DbSet<TbNganh> TbNganhs { get; set; }
        public virtual DbSet<TbNguoiDung> TbNguoiDungs { get; set; }
        public virtual DbSet<TbSlide> TbSlides { get; set; }
        public virtual DbSet<TbThiSinh> TbThiSinhs { get; set; }
        public virtual DbSet<TbThongBao> TbThongBaos { get; set; }
        public virtual DbSet<TbTinh> TbTinhs { get; set; }
        public virtual DbSet<TbTinTuc> TbTinTucs { get; set; }
        public virtual DbSet<TbTruongTHPT> TbTruongTHPTs { get; set; }
        public virtual DbSet<TbXepLoaiH> TbXepLoaiHS { get; set; }
        public virtual DbSet<TbMailServer> TbMailServers { get; set; }
        public virtual DbSet<TbTruongDH> TbTruongDHs { get; set; }
        public virtual DbSet<TbKhoiThi_MonTotNghiep> TbKhoiThi_MonTotNghieps { get; set; }
        public virtual DbSet<TbThiSinh_BacDaoTao> TbThiSinh_BacDaoTaos { get; set; }
        public virtual DbSet<TbThiSinh_Truong> TbThiSinh_Truongs { get; set; }
        public virtual DbSet<TbThongKe> TbThongKes { get; set; }
        public virtual DbSet<TbLogService> TbLogServices { get; set; }
        public virtual DbSet<TbTinTucTrangChu> TbTinTucTrangChus { get; set; }

        public virtual DbSet<TbThoiGian> TbThoiGians { get; set; }

        public virtual DbSet<TbBacDaoTao> TbBacDaoTaos { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<TbHeDaoTao>()
                .HasMany(e => e.TbBacDaoTaos)
                .WithRequired(e => e.TbHeDaoTao)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbChucNang>()
                .Property(e => e.Link)
                .IsUnicode(false);

            modelBuilder.Entity<TbChucNang>()
                .HasMany(e => e.TbChucNang_Quyen)
                .WithRequired(e => e.TbChucNang)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbDanToc>()
                .HasMany(e => e.TbThiSinhs)
                .WithRequired(e => e.TbDanToc)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbDiemTotNghiep>()
                .Property(e => e.MaTS)
                .IsFixedLength();

            modelBuilder.Entity<TbDoiTuongUuTien>()
                .HasMany(e => e.TbThiSinhs)
                .WithRequired(e => e.TbDoiTuongUuTien)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbBacDaoTao>()
                .HasMany(e => e.TbThiSinh_BacDaoTaos)
                .WithRequired(e => e.TbBacDaoTao)
                .WillCascadeOnDelete(false);


            modelBuilder.Entity<TbKhoa>()
                .HasMany(e => e.TbNganhs)
                .WithRequired(e => e.TbKhoa)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbKhoiThi>()
                .Property(e => e.MaKhoiThi)
                .IsFixedLength();

            modelBuilder.Entity<TbKhoiThi>()
                .Property(e => e.TenKhoiThi)
                .IsFixedLength();

            modelBuilder.Entity<TbKhoiThi>()
                .HasMany(e => e.TbNganhs)
                .WithRequired(e => e.TbKhoiThi)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbKhoiThi>()
                .HasMany(e => e.TbKhoiThi_MonTotNghieps)
                .WithRequired(e => e.TbKhoiThi)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbKhoiThi_MonTotNghiep>()
                .Property(e => e.MaKhoiThi)
                .IsFixedLength();

            modelBuilder.Entity<TbKhuVuc>()
                .Property(e => e.MaKhuVuc)
                .IsFixedLength();

            modelBuilder.Entity<TbKhuVuc>()
                .HasMany(e => e.TbTruongTHPTs)
                .WithRequired(e => e.TbKhuVuc)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbQuyen>()
                .HasMany(e => e.TbChucNang_Quyen)
                .WithRequired(e => e.TbQuyen)
                .HasForeignKey(e => e.MaQuyen)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbQuyen>()
                .HasMany(e => e.TbNguoiDungs)
                .WithRequired(e => e.TbQuyen)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbTheLoai>()
                .Property(e => e.Anh)
                .IsUnicode(false);

            modelBuilder.Entity<TbTheLoai>()
                .HasMany(e => e.TbTinTucs)
                .WithRequired(e => e.TbTheLoai)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbTheLoai>()
                .HasMany(e => e.TbTinTucTrangChus)
                .WithRequired(e => e.TbTheLoai)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbMonTotNghiep>()
                .HasMany(e => e.TbDiemTotNghieps)
                .WithRequired(e => e.TbMonTotNghiep)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbMonTotNghiep>()
                .HasMany(e => e.TbKhoiThi_MonTotNghieps)
                .WithRequired(e => e.TbMonTotNghiep)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbNganh>()
                .Property(e => e.MaKhoiThi)
                .IsFixedLength();

            modelBuilder.Entity<TbNganh>()
                .HasMany(e => e.TbChuyenNganhs)
                .WithRequired(e => e.TbNganh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbChuyenNganh>()
                .Property(e => e.MaChuyenNganh)
                .IsFixedLength();
            
            modelBuilder.Entity<TbChuyenNganh>()
                .HasMany(e => e.TbThiSinhs)
                .WithRequired(e => e.TbChuyenNganh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbNguoiDung>()
                .Property(e => e.TenDangNhap)
                .IsFixedLength();

            modelBuilder.Entity<TbHuyen>()
               .Property(e => e.MaHuyen)
               .IsFixedLength();

            modelBuilder.Entity<TbHuyen>()
               .Property(e => e.MaTinh)
               .IsFixedLength();

            modelBuilder.Entity<TbNguoiDung>()
                .Property(e => e.MatKhau)
                .IsFixedLength();

            modelBuilder.Entity<TbSlide>()
                .Property(e => e.Anh)
                .IsUnicode(false);

            modelBuilder.Entity<TbThiSinh>()
                .Property(e => e.MaTS)
                .IsFixedLength();

            modelBuilder.Entity<TbThiSinh>()
                .Property(e => e.MaHuyen)
                .IsFixedLength();

            modelBuilder.Entity<TbThiSinh>()
                .Property(e => e.MaChuyenNganh)
                .IsFixedLength();

            modelBuilder.Entity<TbThiSinh>()
                .Property(e => e.SoDienThoai)
                .IsFixedLength();

            modelBuilder.Entity<TbThiSinh>()
                .Property(e => e.CMND)
                .IsFixedLength();

            modelBuilder.Entity<TbThiSinh>()
                .Property(e => e.NamTotNghiep)
                .IsFixedLength();

            modelBuilder.Entity<TbThiSinh>()
                .Property(e => e.Anh)
                .IsUnicode(false);

            modelBuilder.Entity<TbThiSinh>()
                .Property(e => e.SBD)
                .IsFixedLength();

            modelBuilder.Entity<TbThiSinh>()
                .Property(e => e.MaTruongDH)
                .IsFixedLength();

            modelBuilder.Entity<TbThiSinh>()
                .HasMany(e => e.TbDiemTotNghieps)
                .WithRequired(e => e.TbThiSinh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbThiSinh>()
                .HasMany(e => e.TbThiSinh_Truongs)
                .WithRequired(e => e.TbThiSinh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbThiSinh_BacDaoTao>()
                .Property(e => e.MaTS)
                .IsFixedLength();

            
            modelBuilder.Entity<TbThiSinh_Truong>()
                .Property(e => e.MaTS)
                .IsFixedLength();

            modelBuilder.Entity<TbThongBao>()
                .Property(e => e.NguoiGui)
                .IsFixedLength();

            modelBuilder.Entity<TbThongBao>()
                .Property(e => e.NguoiNhan)
                .IsFixedLength();

            modelBuilder.Entity<TbTinh>()
                .Property(e => e.MaTinh)
                .IsFixedLength();

            modelBuilder.Entity<TbTinTuc>()
                .Property(e => e.AnhDaiDien)
                .IsUnicode(false);

            modelBuilder.Entity<TbTinh>()
                .HasMany(e => e.TbTruongTHPTs)
                .WithRequired(e => e.TbTinh)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbTruongTHPT>()
                .Property(e => e.MaTinh)
                .IsFixedLength();

            modelBuilder.Entity<TbTruongTHPT>()
                .Property(e => e.MaKhuVuc)
                .IsFixedLength();

            modelBuilder.Entity<TbTruongTHPT>()
                .Property(e => e.MaTruong)
                .IsFixedLength();

            //modelBuilder.Entity<TbTruongTHPT>()
            //    .HasMany(e => e.TbThiSinhs)
            //    .WithRequired(e => e.TbTruongTHPT)
            //    .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbTruongDH>()
                .Property(e => e.MaTruongDH)
                .IsFixedLength();

            modelBuilder.Entity<TbTruongDH>()
                .HasMany(e => e.TbThiSinhs)
                .WithRequired(e => e.TbTruongDH)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TbTruongTHPT>()
                .HasMany(e => e.TbThiSinh_Truongs)
                .WithRequired(e => e.TbTruongTHPT)
                .WillCascadeOnDelete(false);
        }
    }
}
